package com.ice.cloud.hotelManagement.sentinelController;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.ice.cloud.hotelManagement.fallbak.MyFallback;
import com.ice.cloud.hotelManagement.serviceSentinel.ConsultingRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.persistence.criteria.CriteriaBuilder;

@RestController
@RequestMapping("/flowControl")
public class FlowControlController {

/*     @GetMapping("f1")
    public String f1(){
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "f1--------------";
    } */

/*     @GetMapping("read")
    public String read(){
        return "read--------------";
    }

    @GetMapping("write")
    public String write(){
        return "write--------------";
    } */


 /*    @Autowired
    ConsultingRoomService consultingRoomService;

    @GetMapping("patientInfo")
    public String patientInfo(){
        consultingRoomService.consultingRoomInto();
        return "patientInfo--------------";
    }

    @GetMapping("doctorInfo")
    public String doctorInfo(){
        consultingRoomService.consultingRoomInto();
        return "doctorInfo--------------";
    }
 */


  /*   @GetMapping("/blockHandlerTest")
    @SentinelResource(value = "blockHandlerTest",blockHandler = "handleException")
    public String blockHandlerTest(){
        return  "我就是你要的数据";
    }
    public String handleException(BlockException exception){
        return "服务器响应无果";
    }
 */

/*     // 服务降级

    @GetMapping("/fallbackTest")
    @SentinelResource(value = "fallbackTest",fallbackClass = MyFallback.class,fallback = "handlerFallback2")
    public String fallbackTest(@RequestParam("id")Integer id){
        if(id<0){
            throw  new RuntimeException("id不能为负数");
        }
        return "你好呀";
    }

    // public String handlerFallback(@RequestParam("id")Integer id,Throwable e){
    //     System.out.println("====>" + e);
    //     return "我错了";
    // } */

/*
    // 热点规则
    @GetMapping("/hotkey")
    @SentinelResource(value="hotkey",blockHandler = "dealHandlerHokey")
    public String hokey (@RequestParam(value = "a",required = false) String a,
                         @RequestParam(value = "b",required = false) String b){
        return "正常返回结果";
    }
    public String dealHandlerHokey(String a,String b,BlockException exception){
        return "不好意思，限流啦";
    } */



    /*
    // 授权规则
    @GetMapping(value = "/backList")
    public String blackList(){
        return "授权规则";
    }
    */

    //  持久化配置
    @GetMapping(value = "config_f1")
    public String f1_config(){
        return "f1_config_ok";
    }





















}
